import {wxRequest} from '../../../utils/server.js';


const _wxRequest = new wxRequest();
const app = getApp()
Page({
  data: {
    imgUrl: app.globalData.imgUrl,
    addresslist:[],
    cententDetail:{}
  },

  onLoad: function(options) {
    this.avatar = this.selectComponent("#avatar"); 

  },

  addressDetail: function (e) {
    this.setData({
      addresslist: e.detail
    })
  },

  onShow: function() {
    this.getUserInfo()
  }, 

  //发布员工
  formSubmit: function(e) {
    var formdata = e.detail.value;
    console.log(this.avatar.data.picslist.imgPath, 'picslist')
    formdata.id = this.data.cententDetail.id
    formdata.avatar = this.avatar.data.picslist.imgPath;
    //如果真是姓名为空，则同步昵称过去
    if (!this.data.cententDetail.nickname){
      formdata.nickname = formdata.realName
    }

    var addresslist = this.data.addresslist
    if (addresslist && addresslist.length > 0) {
      formdata.prov = addresslist[0].name
      formdata.proId = addresslist[0].code
      formdata.city = addresslist[1].name
      formdata.cityId = addresslist[1].code
      formdata.disName = addresslist[2].name
      formdata.disId = addresslist[2].code
    }

   
    if (formdata.nickname == '') {
      wx.showToast({
        icon: 'none',
        title: '昵称不能为空',
      })
      return
    }

    
    //修改 
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + "/sys/protected/comm/beanCrud/auth.UserVO/update",
      // url: app.globalData.apiUrl + "/odr/protected/customer/update",
      method: 'POST',
      data: formdata
    }, (res) => {
      wx.showToast({
        title: "修改成功"
      })
      setTimeout(() => {
        wx.navigateBack({})
      }, 1500)
    })
  },


  goback: function() {
    wx.navigateBack({ })
  },


//查询用户信息 

  getUserInfo:function(){
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + "/sys/protected/comm/beanCrud/auth.UserVO/getById/"+wx.getStorageSync('userInfo').id, 
      method: 'get', 
    }, (res) => { 
      this.setData({
        cententDetail: res.vo,
      })
      this.avatar.setData({
        picslist:{
          imgPath: res.vo.avatar
        }
      })
    })
  }

})